package com.iflytek.erp.base.service.impl;

import com.iflytek.erp.base.entity.BaseDataStoreCenter;
import com.iflytek.erp.base.dao.BaseDataStoreCenterDao;
import com.iflytek.erp.base.service.BaseDataStoreCenterService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 仓库表(BaseDataStoreCenter)表服务实现类
 *
 * @author makejava
 * @since 2024-11-13 11:30:09
 */
@Service("baseDataStoreCenterService")
public class BaseDataStoreCenterServiceImpl implements BaseDataStoreCenterService {
    @Resource
    private BaseDataStoreCenterDao baseDataStoreCenterDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public BaseDataStoreCenter queryById(Integer id) {
        return baseDataStoreCenterDao.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param baseDataStoreCenter 实例对象
     * @return 实例对象
     */
    @Override
    public BaseDataStoreCenter insert(BaseDataStoreCenter baseDataStoreCenter) {
        baseDataStoreCenterDao.insert(baseDataStoreCenter);
        return baseDataStoreCenter;
    }

    /**
     * 修改数据
     *
     * @param baseDataStoreCenter 实例对象
     * @return 实例对象
     */
    @Override
    public BaseDataStoreCenter update(BaseDataStoreCenter baseDataStoreCenter) {
        int num = baseDataStoreCenterDao.update(baseDataStoreCenter);
        if (num>0){
            return this.queryById(baseDataStoreCenter.getId());
        }else{
            return  null;
        }

    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        throw new RuntimeException("模拟删除失败的异常");
//        return baseDataStoreCenterDao.deleteById(id) > 0;
    }

    /**
     * 查询列表
     *
     * @param id
     * @param name
     * @param status
     * @return
     */
    @Override
    public List<BaseDataStoreCenter> list(Integer id, String name, Integer status) {
        List<BaseDataStoreCenter> list = baseDataStoreCenterDao.list(id, name, status);
        return list;
    }
}
